<template>
  <div id="app">
    <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <h3 class="login_title">发布任务</h3>
      <el-form-item label="标题" prop="title" >
        <el-input type="text" v-model="ruleForm.title" autocomplete="off" placeholder="请输入任务标题"></el-input>
      </el-form-item>
      <el-form-item label="任务内容" prop="content" >
        <el-input type="textarea" :rows="8" v-model="ruleForm.content" autocomplete="off" placeholder="请输入任务内容"></el-input>
      </el-form-item>
      <el-form-item label="任务类别" prop="tag_id" >
<!--        <el-input  v-model="ruleForm.tag_id" autocomplete="off" placeholder="请输入任务类别"></el-input>-->
<!--        <span>1.快递代取 2.事务代办</span>-->
        <el-radio v-model="ruleForm.tag_id" label="1" @click="Select1">快递代取</el-radio>
        <el-radio v-model="ruleForm.tag_id" label="2" @click="Select2">事务代办</el-radio>
      </el-form-item>
      <el-form-item label="酬金" prop="reward" >
        <el-input type="number" v-model="ruleForm.reward" autocomplete="off" placeholder="请输入任务酬金"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="Submit">确认发布</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from 'axios'
import router from '../../router'

export default {
  name: `AddTask`,
  data () {
    return {
      ruleForm: {
        title: '',
        content: '',
        tag_id: '',
        reward: ''
      }
    }
  },
  methods: {
    Select1 () {
      this.ruleForm.tag_id = '1'
    },
    Select2 () {
      this.ruleForm.tag_id = '2'
    },
    Submit () {
      axios.post(`user/task/addTask`, {
        title: this.ruleForm.title,
        content: this.ruleForm.content,
        tag_id: this.ruleForm.tag_id,
        reward: this.ruleForm.reward
      }).then(res => {
        if (res.data.status === 100) {
          alert(res.data.data.msg)
        } else {
          alert('发布失败')
        }
      }).catch(err => {
        alert(err)
        router.replace('/login')
      })
    }
  }
}
</script>

<style scoped>
.demo-ruleForm {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 90px auto;
  width: 500px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}

.login_title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}
</style>
